#include <bits/stdc++.h>
#define ll long long 
#define PI pair<int,int>
using namespace std;
int a[200005];
int f[2005][2005];
int main()
{
	/**/freopen("color.in","r",stdin);
	freopen("color.out","w",stdout);/**/
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int T;
	cin>>T;
	while(T--)
	{
		int n;
		cin>>n;
		for(int i=1;i<=n;i++)cin>>a[i];
		memset(f,0,sizeof(f));
		for(int i=2;i<=n;i++)
		{
			for(int j=0;j<=i;j++)
			{
				for(int k=j;k<i;k++)
				f[i][j]=max(f[i-1][j]+(a[k]==a[i]?a[i]:0),f[i][j]);
				for(int k=i-j;k<i;k++)
				f[i][j]=max(f[i-1][j-1]+(a[k]==a[i]?a[i]:0),f[i][j]);
			}
		}
		//for(int i=1;i<=n;i++){for(int j=1;j<=n;j++)cout<<f[i][j]<<' ';cout<<'\n';}
		int ans=-1;
		for(int i=1;i<=n;i++)
		ans=max(ans,f[n][i]);
		cout<<ans;
		cout<<'\n';
	}
	return 0;
}
/**







/**/
